home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 19 / Mac Magazin and MacEasy Magazine CD - Issue 19.iso / Wissenschaft & Technik / Open Prolog / Benchmarks next >
Text File  |  1994-05-11  |  2KB  |  84 lines

  1. %Some standard benchmarks
  2.  
  3. nreverse([X|L0],L) :- nreverse(L0,L1),concatenate(L1,[X],L).
  4. nreverse([],[]).
  5.  
  6. concatenate([X|L1],L,[X|L2]) :- concatenate(L1,L,L2).
  7. concatenate([],L,L).
  8.  
  9. list30([1,2,3,4,5,6,7,8,9,10,11,
  10.     12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]).
  11.  
  12. times10(((((((((x*x)*x)*x)*x)*x)*x)*x)*x)*x).
  13. divide10(((((((((x/x)/x)/x)/x)/x)/x)/x)/x)/x).
  14. log10(log(log(log(log(log(log(log(log(log(log(x))))))))))).
  15. ops8((x+1)*(x^2+2)*(x^3+3)).
  16.  
  17. myRepeat(0,X) :- !.
  18. myRepeat(Count,Procedure) :-
  19.     callAndFail(Procedure),
  20.     NewCount is Count-1,!,
  21.     myRepeat(NewCount,Procedure).
  22.     
  23. dummyRepeat(0,X) :- !.
  24. dummyRepeat(Count,Procedure) :-
  25.     dummyCallAndFail(Procedure),
  26.     NewCount is Count-1,
  27.     !,
  28.     dummyRepeat(NewCount,Procedure).
  29. dummyCallAndFail(X) :- dummyDoOnce(X),fail.
  30. dummyCallAndFail(_).
  31.  
  32. dummyDoOnce(X) :- call(module(X)),!.    %i.e. a do-nothing call
  33.  
  34. callAndFail(X) :- doOnce(X),fail.
  35. callAndFail(_).
  36.  
  37. doOnce(X) :- call(X),!.
  38.  
  39. time(Count,Procedure) :-
  40.     nonvar(Procedure),
  41.     S is cputime,
  42.     myRepeat(Count,Procedure),
  43.     T is cputime,
  44.     dummyRepeat(Count,Procedure),
  45.     Ctime is cputime-T,
  46.     !,
  47.     Etime is T-S,
  48.     Atime is Etime-Ctime,
  49.     telling(CurrentOutput),
  50.     tell(user),
  51.     write('Elapsed time: '),
  52.     write(Atime),write(' mS'),
  53.     tell(CurrentOutput).
  54.  
  55. d(U+V,X,DU+DV) :- !, d(U,X,DU),d(V,X,DV).
  56. d(U-V,X,DU-DV) :- !, d(U,X,DU),d(V,X,DV).
  57. d(U*V,X,DU*V+U*DV) :- !,d(U,X,DU),d(V,X,DV).
  58. d(U/V,X,(DU*V-U*DV)/V^2) :- !,d(U,X,DU),d(V,X,DV).
  59. d(U^N,X,DU*N*U^N1) :- integer(N),N1 is N-1,d(U,X,DU).
  60. d(-U,X,-DU) :- !,d(U,X,DU).
  61. d(exp(U),X,exp(U)*DU) :- !,d(U,X,DU).
  62. d(log(U),X,DU/U) :- !,d(U,X,DU).
  63. d(X,X,1) :- !.
  64. d(C,X,0).
  65.  
  66. list50(
  67. [27,74,17,33,94,18,46,83,65,2,
  68. 32,53,28,85,99,47,28,82,6,11,
  69. 55,29,39,81,90,37,10,0,66,51,
  70. 7,21,85,27,31,63,75,4,95,99,
  71. 11,28,61,74,18,92,40,53,59,8]).
  72.  
  73. qsort([X|L],R,R0) :-
  74.     partition(L,X,L1,L2),
  75.     qsort(L2,R1,R0),
  76.     qsort(L1,R,[X|R1]).
  77. qsort([],R,R).
  78.  
  79. partition([X|L],Y,[X|L1],L2) :- X=<Y,!,
  80.     partition(L,Y,L1,L2).
  81. partition([X|L],Y,L1,[X|L2]) :- 
  82.     partition(L,Y,L1,L2).
  83. partition([],_,[],[]).
  84.